﻿package mlc.haxe.output;
import haxe.Log;
import haxe.PosInfos;
import mlc.haxe.output.ConsoleOutputHandler;

/**
 * An output handler that "traces" all the output from the console.
 */
class TraceOutputHandler implements ConsoleOutputHandler {
	private var clear:Void -> Void;
	private var trace:Dynamic -> PosInfos -> Void;
	/**
	 * Creates a new trace output handler. This trace output handler will use the trace method that has been set to Log.trace at
	 * the time this object is constructed.
	 */
	public function new():Void {
		// Store the trace and the clear method. This way, those methods method may be replaced without breaking this output
		// handler.
		clear = Log.clear;
		trace = Log.trace;
	}
	public function clearOutput():Void {
		clear();
	}
	#if debug
	private function toString():String {
		return "[ConsoleOutputHandler]";
	}
	#end
	public function writeAdvancedString(value:String, color:Int, breakline:Bool):Void {
		this.trace(value, null);
	}
	public function writeBool(value:Bool, positionInformation:PosInfos):Void {
		this.trace(value, positionInformation);
	}
	public function writeFloat(value:Float, positionInformation:PosInfos):Void {
		this.trace(value, positionInformation);
	}
	public function writeInt(value:Int, positionInformation:PosInfos):Void {
		this.trace(value, positionInformation);
	}
	public function writeNull(positionInformation:PosInfos):Void {
		this.trace("null", positionInformation);
	}
	public function writeString(value:String, positionInformation:PosInfos):Void {
		this.trace(value, positionInformation);
	}
	public function writeXml(value:Xml, positionInformation:PosInfos):Void {
		this.trace(value, positionInformation);
	}
}